/**
 * 后台功能
 * */


(function () {
})();


//获取功能列表
function getList(){
    $.ajax({
        type: apis.patientIndex.method,
        url: apis.patientIndex.url,
        data: {},
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '';
                h += '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            tbody.html(getHtml(res.data));
            $('#pageTotal').html(res.total);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//HTML
function getHtml(d){
    var h = '', i, ii, pats;
    for (i = 0; i < d.length; i ++) {
        pats = d[i].pat_list;
        h += '<tr class="text-c">';
        h += '<td>' + d[i].id + '</td>';
        h += '<td>' + d[i].realname + '</td>';
        if (d[i].head = '') {
            h += '<td><img src="' + d[i].head + '" height="50"/></td>';
        } else {
            h += '<td>-</td>';
        }
        h += '<td style="clear: both;">';
        if (pats.length > 0) {
            for (ii = 0; ii < pats.length; ii ++) {
                h += '<a href="javascript:;" style="color: #0088cc; font-size: 16px;" onclick="lay_show(\'病历详情\',\'pat-show.html\',' + pats[ii].id + ');">';
                h += pats[ii].title;
                h += '</a><br>';
            }
        }
        h += '</td>';
        h += '<td>' + d[i].uptime + '</td>';
        //h += '<td class="f-14">';
        //h += '<a href="javascript:;" onclick="lay_edit(\'编辑\',\'admin-edit.html\', ' + d[i].id + ')">';
        //h += '修改';
        ////h += '<i class="Hui-iconfont">&#xe6df;</i>';
        //h += '</a>';
        //h += ' &nbsp; ';
        //h += '<a href="javascript:;" onclick="lay_pwd(\'修改密码\',\'admin-pwd.html\', ' + d[i].id + ')">';
        //h += '修改密码';
        ////h += '<i class="Hui-iconfont">&#xe6df;</i>';
        //h += '</a>';
        //h += '</td>';
        h += '</tr>';
    }
    return h;
}


//详情
function lay_show(title,url,id,w,h){
    url += '?id=' + id;
    layer_show(title,url,w,h);
}


//获取一个
function getOne(){
    $.ajax({
        type: apis.patientOne.method,
        url: apis.patientOne.url,
        data: { id: id },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            var d = res.data;
            $('#title').html(d.title);
            $('#desc').html(d.detail);
            $('#realname').html(d.realname);
            $('#sex').html(d.sex==1?'男':'女');
            $('#age').html(d.age);
            var imgList = d.imgList;
            var h = '', i;
            for (i = 0; i < imgList.length; i ++) {
                h += '<img src="' + imgList[i] + '"/>';
            }
            $('#imgList').html(h);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}